<?php
/**
 * @category 	GroupDao.php
 * @author 		Sung Hoon, Cho (akdddnet@gmail.com)
 * @since		2011. 5. 2.
 * @license		BSD License
 * @version		0.1
 */
 
global $CFG;
require_once $CFG->FW_DIR."/mvc/Dao.php";
 
class GroupDao extends Dao {
	
 	function __construct(array $db_type = null) {
 		parent::__construct($db_type);	
 	}
 	
 	
 	function index(DTO $dto) {
 		$query = "
 			SELECT 
 						*
 			FROM 		groups
 			WHERE		1 = 1
 			ORDER BY 	g_parent, g_depth, g_order
 		";
 		
 		$dto->list = $this->db->query($query)->fetchAll();
 		
 		return $dto;
 	}
 	
	function view(DTO $dto) {
 		$query ="
 				SELECT		*
 				FROM 		groups
 				WHERE		1 = 1
 				AND			g_seq = :g_seq
 		";
 		
 		$bind = array(
 				"g_seq"=>$dto->eb->g_seq
 		);
 		
 		$dto->obj = $this->db->query($query, $bind)->fetch();
 		
 		return $dto;
 	}
 	
 	
 	function doAdd(DTO $dto) {
 		$query = "
 				INSERT INTO groups
 					(g_name, g_intro, g_cdate)
 				VALUES
 					(:g_name, :g_intro, now())
 		";
 		
 		$bind = array(
 			 "g_name"=>$dto->eb->g_name
 			,"g_intro"=>$dto->eb->g_intro
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	
	function doModify(DTO $dto) {
 		$query = "
 				UPDATE 	groups SET
	 					 g_name 		= :g_name
	 					,g_intro		= :g_intro
 				WHERE	1 = 1
 				AND		g_seq			= :g_seq
 		";
 		
 		$bind = array(
 			 "g_seq"=>$dto->eb->g_seq
 			,"g_name"=>$dto->eb->g_name
 			,"g_intro"=>$dto->eb->g_intro
 			
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
 	
 	function doDelete(DTO $dto) {
 		$query = "
 			DELETE 
 			FROM 	groups 
 			WHERE	1 = 1
			AND		g_seq = :g_seq  			
 		";
 		
 		$bind = array(
 			"g_seq"=>$dto->eb->g_seq
 		);
 		
 		$dto->rc = $this->db->query($query, $bind)->rowCount();
 		
 		return $dto;
 	}
}